package demo.DataStrucAndAlgo.Easy_pritice;

import java.util.*;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/3-08-03-9:50
 * @Description：demo.DataStrucAndAlgo.Easy_pritice   斗地主案例
 */
public class fightingTheLand {
    static List<String> card  = new ArrayList<>();
    public static void main(String[] args) {

        //生成牌
        List<Integer> index = new ArrayList<>();
        String[] num = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        String[] huase = {"♣","♥","♦","♠"};
        int k = 0;
        for (int i = 0; i < num.length; i++) {
            for (int j = 0; j < huase.length; j++) {
                card.add(huase[j] + num[i]);
                index.add(k++);
            }
        }
        card.add("小王");
        index.add(k++);
        card.add("大王");
        index.add(k);
        System.out.println(card);
        Collections.shuffle(index);
        List<Integer> player1 = new ArrayList<>();
        List<Integer> player2 = new ArrayList<>();
        List<Integer> player3 = new ArrayList<>();
        List<Integer> dipai = new ArrayList<>();
        for (int i = 0; i < card.size(); i++) {
            if(i >= 51){
                dipai.add(index.get(i));
            }else if(i % 3 == 1){
                player1.add(index.get(i));
            }else if(i % 3 == 2){
                player2.add(index.get(i));
            }else{
                player3.add(index.get(i));
            }
        }
        Collections.sort(player1);
        Collections.sort(player2);
        Collections.sort(player3);

        System.out.println("玩家一的牌：");
        showCard(player1);

        System.out.println("玩家二的牌：");
        showCard(player2);

        System.out.println("玩家三的牌：");
        showCard(player3);

        System.out.println("底牌：");
        showCard(dipai);
    }

    public static void showCard(List<Integer> player) {
        int index;
        for (int i = 0; i < player.size(); i++) {
            index = player.get(i);
            if(i == 0){
                System.out.print("[" + card.get(index));
            }else{
                System.out.print(", " + card.get(index));
            }
        }
        System.out.println("]");
    }
}
